<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input id="input" />
    <button id="btn">按钮</button>
    <script>
      function debounce(func) {
        let timer = null
        return (e) => {
          if (timer) clearTimeout(timer)
          timer = setTimeout(() => {
            func && func(e)
          }, 2000)
        }
      }

      input.oninput = debounce((e) => {
        console.log(e)
      })

      btn.onclick = debounce(function (e) {
        console.log('click', e)
      })
    </script>
  </body>
</html>
